using Naptime.Extensions;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Voodoo.GameOps;
using Voodoo.Pattern;

public class FinishScreen : MonoBehaviour
{
	[SerializeField]
	private TextMeshProUGUI levelTxt;

	[SerializeField]
	private TextMeshProUGUI moneyTxt;

	[SerializeField]
	private Button continueBtn;

	private const string TOTAL_FINISHED_LEVELS = "TOTALAMOUNTOFFINISHEDLEVELS";

	private int _moneyValue;

	public void Setup(int lvl, int money)
	{
		SingletonMB<GameManager>.Instance.AnyWindowActive = true;
		base.gameObject.SetActive(value: true);
		continueBtn.onClick.RemoveAllListeners();
		continueBtn.onClick.AddListener(Continue);
		levelTxt.text = "LEVEL " + lvl;
		moneyTxt.text = "+" + money;
		_moneyValue = money;
	}

	private void Continue()
	{
		SteamAchievements.UnlockAchievement(21.ToString());
		int num = NintendoPlayerPrefs.GetInt("TOTALAMOUNTOFFINISHEDLEVELS", 0) + 1;
		NintendoPlayerPrefs.SetInt("TOTALAMOUNTOFFINISHEDLEVELS", num);
		if (num >= 2)
		{
			SteamAchievements.UnlockAchievement(22.ToString());
		}
		if (num >= 3)
		{
			SteamAchievements.UnlockAchievement(23.ToString());
		}
		if (num >= 4)
		{
			SteamAchievements.UnlockAchievement(24.ToString());
		}
		if (num >= 5)
		{
			SteamAchievements.UnlockAchievement(25.ToString());
		}
		SingletonMB<GameManager>.Instance.AnyWindowActive = false;
		base.gameObject.SetActive(value: false);
		InventoryManager.Instance.AddPrestigePoints(5f);
		NintendoPlayerPrefs.SetFloat("Money", (float)_moneyValue + NintendoPlayerPrefs.GetFloat("Money", 0f) + (float)SingletonMB<GameManager>.Instance.DeltaMoney);
		Object.FindObjectOfType<Money>()?.SetActive(active: false);
		Object.FindObjectOfType<PrestigePointsCounter>()?.SetActive(active: false);
		SingletonMB<GameManager>.Instance.RestartLevelAfterComplete();
	}

	private void Update()
	{
		if (Singleton<InputController>.Instance.Action)
		{
			Continue();
		}
	}
}
